package com.ruoyi.classai.api;

import com.ruoyi.classai.domain.EwcChapterResource;
import com.ruoyi.classai.domain.dto.chapterresource.EwcChapterResourceAddDto;
import com.ruoyi.classai.domain.dto.chapterresource.EwcChapterResourceQueryDto;
import com.ruoyi.classai.service.IEwcChapterResourceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

/**
 * 老师资源库
 */
@Tag(name = "老师资源库")
@RestController
@RequestMapping("/api/teacherResource")
public class TeacherResourceApi extends BaseController {

    @Autowired
    private IEwcChapterResourceService ewcChapterResourceService;

    /**
     * 查询老师资源库列表
     */
    @Operation(summary = "查询老师资源库列表")
    @GetMapping("/list")
    public TableDataInfo list(EwcChapterResourceQueryDto dto) {
        startPage();
        List<EwcChapterResource> list = ewcChapterResourceService.selectChapterResourceList(dto);
        return getDataTable(list);
    }


    /**
     * 获取老师资源库详细信息
     */
    @Operation(summary = "获取老师资源库详细信息")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success("查询成功", ewcChapterResourceService.getChapterResourceById(id));
    }

    /**
     * 新增老师资源库
     */
    @Operation(summary = "新增老师资源库")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Validated EwcChapterResourceAddDto dto) {
        ewcChapterResourceService.insertChapterResource(dto);
        return AjaxResult.success("操作成功！");
    }

    /**
     * 修改老师资源库
     */
    @Operation(summary = "修改老师资源库")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody @Valid EwcChapterResourceAddDto dto) {
        ewcChapterResourceService.updateChapterResource(dto);
        return AjaxResult.success("操作成功！");
    }

    /**
     * 删除老师资源库
     */
    @Operation(summary = "删除老师资源库")
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        List<String> list = Arrays.asList(ids);
        ewcChapterResourceService.deleteChapterResourceByIds(list);
        return AjaxResult.success("操作成功！");
    }

    /**
     * 查询资源库列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/resourceList")
    @Operation(summary = "查询资源库列表")
    public AjaxResult resourceList(@RequestBody EwcChapterResourceQueryDto dto) {
        List<EwcChapterResource> list = ewcChapterResourceService.selectChapterResourceList(dto);
        return AjaxResult.success("操作成功！", list);
    }
}